package com.ellricky.baselib.ui.order

import android.widget.ImageView
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.adapter.SmartViewHolder
import com.ellricky.baselib.R
import com.ellricky.baselib.entity.VisitListInfo
import com.ellricky.baselib.util.Ext.load

class VisitListAdapter :
    BaseRecyclerAdapter<VisitListInfo>(R.layout.base_adapter_visit_list) {
    override fun onBindViewHolder(holder: SmartViewHolder, data: VisitListInfo, p2: Int) {
        if (data.imgs != null) {
            when (data.imgs.size) {
                1 -> {
                    holder.visible(R.id.iv_bill_1)
                    holder.gone(R.id.iv_bill_2)
                    holder.gone(R.id.iv_bill_3)
                    holder.itemView.findViewById<ImageView>(R.id.iv_bill_1)
                        .load(data.imgs[0], placeholder = R.drawable.base_bg_image_placeholder)
                }
                2 -> {
                    holder.visible(R.id.iv_bill_1)
                    holder.visible(R.id.iv_bill_2)
                    holder.gone(R.id.iv_bill_3)
                    holder.itemView.findViewById<ImageView>(R.id.iv_bill_1)
                        .load(data.imgs[0], placeholder = R.drawable.base_bg_image_placeholder)
                    holder.itemView.findViewById<ImageView>(R.id.iv_bill_2)
                        .load(data.imgs[1], placeholder = R.drawable.base_bg_image_placeholder)
                }
                3 -> {
                    holder.visible(R.id.iv_bill_1)
                    holder.visible(R.id.iv_bill_2)
                    holder.visible(R.id.iv_bill_3)
                    holder.itemView.findViewById<ImageView>(R.id.iv_bill_1)
                        .load(data.imgs[0], placeholder = R.drawable.base_bg_image_placeholder)
                    holder.itemView.findViewById<ImageView>(R.id.iv_bill_2)
                        .load(data.imgs[1], placeholder = R.drawable.base_bg_image_placeholder)
                    holder.itemView.findViewById<ImageView>(R.id.iv_bill_3)
                        .load(data.imgs[2], placeholder = R.drawable.base_bg_image_placeholder)
                }
                else -> {
                    holder.gone(R.id.iv_bill_1)
                    holder.gone(R.id.iv_bill_2)
                    holder.gone(R.id.iv_bill_3)
                }
            }
        }

        holder.text(R.id.tv_return_time, "日期：${data.mr_createtime}")
            .text(R.id.tv_return_name, "回访人：${data.return_user_name}")
    }
}